<!DOCTYPE html>
<html>
<head>
	<title></title>
<script type="text/javascript" src="__PUBLIC__/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/jquery.luara.0.0.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/qh_goods.css">
</head>
<body>
	<div class="qh_header">
		<div class="qh_header_login">您好，欢迎来到灷窍乾商城！</div>
	</div>
	<div class="qh_search">

			<img src="__PUBLIC__/home/images/goods/goods_logo.png" class="qh_search_logo">
			<input type="text" name="name" id = "name" style="margin-left:355px">
			<button onClick="xxxx();">搜&nbsp;索</button>
		
			<a href="{:U('Goods/index')}" style="width:140px"><img src="__PUBLIC__/home/images/goods/classify.png" style="width:16px;height:16px;margin-bottom:5px;">&nbsp;&nbsp;全部分类</a>
	<script>
	function xxxx(){

	var name=$('#name').val();
	if(name != ""){
		location.href="goods_list/name/"+name;
	}else{
		location.href="goods_list";
	}

	}
	</script>		
	</div>
	<div class="qh_cart">
		<table class="qh_cart_table">
		
			<tr style="background:#f2f2f2;">
					<th style="width:370px;">购物车中的商品</th>
					<th style="width:200px;">商品价格</th>
					<th style="width:200px;">会员价格</th>
					<th style="width:200px;">数量</th>
					<th style="width:200px;">操作</th>
			</tr>
		<form action="{:U('Goods/address_add')}" method="post" id="ffff" onSubmit="return false">
			<volist name="list" id="vo">
			<tr id="ttt{$vo.id}">
				<td>
					<div class="qh_cart_table_img">
						<a href="{:U('Goods/details',array('id'=>$vo['goods_id']))}">
							<img src="{$vo.pic}" style="width:120px;height:120px;">
						</a>
					</div>
					<div class="qh_cart_table_title">
						<a href="{:U('Goods/details',array('id'=>$vo['goods_id']))}">{$vo.name}</a>
					</div>
				</td>
				<td style="font-weight:bold">￥{$vo.all_money}元</td>
				<td style="font-weight:bold">￥{$vo.money}元</td>
				<td>
					<input type="hidden" value="{$vo.all_money}" id="shangpinmoney{$vo.id}" />
					<input type="hidden" value="{$vo.money}" id="huiyuanmoney{$vo.id}" />
					<input type="hidden" value="{$vo.num}" name="{$vo.id}" id="nn_id{$vo.id}"/>
					<!-- 	<input type="hidden" value="{$vo.id}" name="{$vo.id}">-->
					<button  onClick="subxxx({$vo['id']});"  style="background:white;border:1px solid #ccc;width:22px;height:22px">-</button>&nbsp;
					<div class="qh_goods_content_right_number_div" style="border:1px solid #bbb;height:20px;color:#B90202" id="buy_num{$vo.id}">{$vo.num}</div>&nbsp;
					<button  onClick="add({$vo['id']});" style="background:white;border:1px solid #ccc;width:22px;height:22px">+</button>
				</td>
				<td>
					<button class="qh_cart_delete"  onClick="del_cart({$vo['id']});">删&nbsp;除</button>
				</td>
			</tr>
			</volist>	
		
			
			
			
		</table>

		
		
	</div>
	<div class="qh_account">
		<div class="qh_account_div">
			总商品价格：￥<span id="all_money">{$all_money|default="无"}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;总会员价格：￥<span id="money">{$money|default="无"}</span>
			<a onClick="jiesuan();">马&nbsp;上&nbsp;结&nbsp;算</a>
			<!-- {:U('Goods/address_add')}-->
		</div>
	</div>
</form>
	<!-- //////////////////////////////////////////////////////////////////////////////////////// -->
		<script>
			function jiesuan(){
				$('#ffff').removeAttr("onSubmit");
				$("#ffff").submit();
			}
		</script>
	
	
	<!-- //////////////////////////////////////////////////////////////////////////////////////// -->

<script>
function del_cart(id){
	var url="{:U('Goods/del_cart')}";
	$.post(url,{'id':id},function(data){
			alert(data.info);
			if(data.status == 1){
			
					
					var num=$('#buy_num'+id).html();
					var sp=$('#shangpinmoney'+id).val();
				
					sp=Number(sp)*Number(num);
					var hy=$('#huiyuanmoney'+id).val();
					hy=Number(hy)*Number(num);
					var x=$('#all_money').html();
					var y=$('#money').html();
					
					var xx=Number(x)-Number(sp);
						if(xx <= 0){
								xx=0;
						}
					var yy=	Number(y)-Number(hy);
						if(yy <= 0){
							yy=0;
						}
				$('#all_money').html(xx);
				$('#money').html(yy);
					$("#ttt"+id).remove();
			}
					
	});
}



function add(id){
		
		var num = $("#buy_num"+id).html();
		
		
		if(num == ''){
			num = 0;
		}
		num = Number(num);
	
		var num_now = num+1;
		$("#buy_num"+id).html(num_now);
		$('#nn_id'+id).val(num_now);
		var sp=$('#shangpinmoney'+id).val();
		var hy=$('#huiyuanmoney'+id).val();
		var x=$('#all_money').html();
		var y=$('#money').html();
		
		
		$('#all_money').html(Number(sp)+Number(x));
		$('#money').html(Number(hy)+Number(y));
	}
	function subxxx(id){
		
		var num = $("#buy_num"+id).html();
	
		if(num == ''){
			num = 0;
		}
		num = Number(num);

		var num_now = Math.max( num-1,0 );
		if(num_now == 0){
			alert("商品最少数量为1");return;
		}
		//alert(num_now);
		$("#buy_num"+id).html(num_now);
		$('#nn_id'+id).val(num_now);
		if(num-1 < 0){
		
			return;
		}
		var sp=$('#shangpinmoney'+id).val();
		var hy=$('#huiyuanmoney'+id).val();
		var x=$('#all_money').html();
		var y=$('#money').html();
		var xx=Number(x)-Number(sp);
		if(xx < 0){
			xx=0;
		}
		var yy=Number(y)-Number(hy);
		if(yy < 0){
			yy=0;
		}
		
		$('#all_money').html(xx);
		$('#money').html(yy);


	}
</script>		
<div class="qh_footer">Copyright 2017-2018 All  灷窍乾 商城 版权所有</div>
</body>
</html>